﻿using Abp.Application.Services.Dto;
using Abp.AutoMapper;
using Abp.Domain.Repositories;
using Permissions.Employee_RoleApp.Dto;
using Permissions.EmployeeApp;
using Permissions.EmployeeApp.Dto;
using Permissions.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Permissions.Employee_RoleApp
{
    public class Employee_RoleAppService : IEmployee_RoleAppService
    {
        private readonly IRepository<Employee_Role> _employeeRoleRepository;

        public Employee_RoleAppService(IRepository<Employee_Role> employeeRoleRepository)
        {
            _employeeRoleRepository = employeeRoleRepository;
        }

        public void CreateEmployee_Role(CreateEmployee_RoleInput input)
        {
            var employeeRole = new Employee_Role { Employee = input.Employee, Role = input.Role };

            _employeeRoleRepository.Insert(employeeRole);
        }

        public void DeleteEmployee_Role(EntityDto input)
        {
            throw new NotImplementedException();
        }

        //public ListResultDto<Employee_RoleDto> GetEmployees_Role()
        //{
        //    var employe_Roles = _employeeRoleRepository.GetAll();

        //    return new ListResultDto<Employee_RoleDto>(employe_Roles.MapTo<List<Employee_RoleDto>>());
        //}
        public ListResultDto<Employee_RoleDto> GetEmployees_Role(int Id)
        {
            var GetAll = _employeeRoleRepository.GetAll();
            var data= new ListResultDto<Employee_RoleDto>(GetAll.MapTo<List<Employee_RoleDto>>());
            var employe_Roles = new List<Employee_RoleDto>();
            foreach (var item in data.Items)
            {
                if (item.Employee.Id == Id)
                {
                    employe_Roles.Add(item);
                }
            }

            return new ListResultDto<Employee_RoleDto>(employe_Roles);
        }

        public void UpdateEmployee_Role(UpdateEmployee_RoleInput input)
        {
            throw new NotImplementedException();
        }
    }
}
